/**
 * @author Linrui
 * @since 2011-03-05
 * 显示结果分页辅助类
 */
package com.qeado.util;

import java.util.List;

public class PageHelper {

	private int currentpage = 1; // 当前页

	private int nextpage; // 下一页

	private int priviouspage; // 前一页

	private int pagecount = 0; // 共有页数，页总数

	private int recordcount = 0; // 记录的总条数

	private int pageSize = 0; // 每页显示记录数,该值由spring初始化配置注入

	private String condition;

	private String sql;

	private List objList;

	private String pagebar = "";

	public int getCurrentPage() {
		return currentpage;
	}

	public void setCurrentPage(int currentpage) {
		this.currentpage = currentpage;
	}

	public int getNextPage() {
		if (pagecount > currentpage) {
			nextpage = currentpage + 1;
		} else {
			nextpage = currentpage;
		}
		return nextpage;
	}

	public void setNextPage(int nextpage) {
		this.nextpage = nextpage;
	}

	public int getPageCount() {
		if (recordcount % pageSize == 0) {
			pagecount = recordcount / pageSize;
		} else {
			pagecount = recordcount / pageSize + 1;
		}
		return pagecount;
	}

	public void setPageCount() {
		this.pagecount = recordcount / pageSize + 1;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPriviousPage() {
		if (currentpage > 1) {
			priviouspage = currentpage - 1;
		} else {
			priviouspage = currentpage;
		}
		return priviouspage;
	}

	public void setPriviousPage(int priviouspage) {
		this.priviouspage = priviouspage;
	}

	public int getRecordCount() {
		return recordcount;
	}

	public void setRecordCount(int recordcount) {
		this.recordcount = recordcount;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public List getObjList() {
		return objList;
	}

	public void setObjList(List objList) {
		this.objList = objList;
	}

	public String getPagebar() {
		return pagebar;
	}

	public void setPagebar(String url) {
		String strResult = "";
		if (currentpage <= 1) { // 如果list表中记录数可以在一页中显示，则上一页，首页无链接
			strResult = strResult + "首页 上一页 ";
		} else { // 如果结果集中记录数超出一页，则有链接，可以分页显示
			strResult = "<a href='" + url + "&pageNum=1'>首页</a>&nbsp;&nbsp;";
			strResult += "<a href='" + url + "&pageNum="
					+ (this.currentpage - 1) + "'>上一页</a>&nbsp;&nbsp;";
		}
		if (currentpage >= pagecount) { // 如果当前页是显示的最后一页，则下一页，尾页无链接
			strResult += "下一页&nbsp;&nbsp;尾页&nbsp;&nbsp;";
		} else {// 否则，只要记录不是最后一页都有链接实现点击分页
			strResult += "<a href='" + url + "&pageNum="
					+ (this.currentpage + 1) + "'>下一页</a>&nbsp;&nbsp;";
			strResult += "<a href='" + url + "&pageNum=" + this.pagecount
					+ "'>尾页</a>&nbsp;&nbsp;";
		}
		strResult = strResult + "第<font color='red'>" + currentpage
				+ "</font>页（共<font color='red'>" + recordcount
				+ "</font>条记录，共<font color='red'>" + pagecount
				+ "</font>页，每页<font color='red'>" + pageSize
				+ "</font>条记录）";
		if (pagecount >= 1)
			this.pagebar = strResult;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

}
